package com.jhd.fuzhou.util;

import com.alibaba.fastjson.JSON;
import com.jhd.fuzhou.view.login.FuzhouApplication;
import com.jhd.fuzhou.vo.AskingRecord;
import com.jhd.fuzhou.vo.IllegalRecordDtlVo;
import com.jhd.fuzhou.vo.GradeQuestionBankVo;
import com.jhd.fuzhou.vo.QA;
import com.jhd.fuzhou.vo.RecordPDFVo;
import com.jhd.fuzhou.vo.SupervisionInspectionPhotoVo;
import com.jhd.fuzhou.vo.SupervisionInspectionVo;
import com.jhd.fuzhou.vo.Upload;

import net.zigin.commons.util.StringUtil;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


public class DocumentPreview {
    /*文书管理生成文书*/
    public static String superviseOpinion(FuzhouApplication application,String bh, String docTemplateUrl){
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("bh",bh);//编号
        params.put("docTemplateUrl",docTemplateUrl);//文书模板地址
        params.put("orgLevel", application.getOrgLevel());
        params.put("county", application.getCounty());
        String ss= JSON.toJSONString(params);
        return ss;
    }

    /*监督意见书*/
    public static String superviseOpinion(SupervisionInspectionVo supervisionInspectionVo, FuzhouApplication application, String documentNo, String cs, String fileUrl, Upload upload){
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        if(documentNo==null){
            params.put("bh"," ");//编号
        }else{
            params.put("bh",documentNo);//编号
        }
        params.put("docTemplateUrl",fileUrl);//文书模板地址
        params.put("sfzh", supervisionInspectionVo.getCertificateNo());
        params.put("ks", cs);
        params.put("dsr", supervisionInspectionVo.getSupervisedUnitName());//当事人
        params.put("fddbr", supervisionInspectionVo.getLegalRepresentative());//法定代表人
        params.put("jdyj", StringUtil.isNullOrEmpty(supervisionInspectionVo.getSupervisionOpinions())?"": supervisionInspectionVo.getSupervisionOpinions());//监督意见
        params.put("lxdh", supervisionInspectionVo.getContactNumber());//联系电话
        params.put("mz", supervisionInspectionVo.getNation());//民族
        params.put("xb", supervisionInspectionVo.getGender());//性别
        params.put("zw", supervisionInspectionVo.getPosition());//职务
        params.put("dz", supervisionInspectionVo.getManagementAddress());//住址
        if(upload!=null)params.put("litigantSignUrl",upload.getUrl());//当事人签名
        params.put("startYear", supervisionInspectionVo.getInspectStartTime().substring(0,4));
        params.put("startMonth", supervisionInspectionVo.getInspectStartTime().substring(5,7));
        params.put("startDay", supervisionInspectionVo.getInspectStartTime().substring(8,10));
        params.put("startHour", supervisionInspectionVo.getInspectStartTime().substring(11,13));
        params.put("startMin", supervisionInspectionVo.getInspectStartTime().substring(14));
        params.put("jdy1", supervisionInspectionVo.getFirstSupervisorName());
        params.put("jdy2", supervisionInspectionVo.getSecondSupervisorName());//监督员2
        params.put("zfzjhm1", supervisionInspectionVo.getFirstSupervisorNo());
        params.put("zfzjhm2", supervisionInspectionVo.getSecondSupervisorNo());
        params.put("dwmc", StringUtil.isNullOrEmpty(supervisionInspectionVo.getSupervisedUnitName2())?supervisionInspectionVo.getSupervisedUnitName():supervisionInspectionVo.getSupervisedUnitName2());//被监督单位名称
        params.put("ptr", supervisionInspectionVo.getAccompanyName());//陪同人
        params.put("jcjg", supervisionInspectionVo.getSuperviseSector());//检查的单位的所属监督机构
        params.put("orgLevel", application.getOrgLevel());
        params.put("county", application.getCounty());
        List<IllegalRecordDtlVo> illegalRecordDtlVoVoList = supervisionInspectionVo.getIllegalRecordDtlVoList();
        if(illegalRecordDtlVoVoList !=null){
            params.put("enforceBasisVoList",illegalRecordDtlVoVoList);
            List<String> list=new ArrayList<>();
            for (IllegalRecordDtlVo illegalRecordDtlVo : illegalRecordDtlVoVoList) {
                list.add(illegalRecordDtlVo.getSuperviseOpinion());
            }
            params.put("superviseOpinionList",list);//监督意见列表
        }
        String ss= JSON.toJSONString(params);
        return ss;
    }
    /*询问笔录*/
    public static String enquiryRecord(SupervisionInspectionVo supervisionInspectionVo,FuzhouApplication application, String fileUrl, Upload upload1, Upload upload2, Upload upload3, AskingRecord askingRecord,List<QA> qaList){
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("docTemplateUrl",fileUrl);
        params.put("bh"," ");//编号
        params.put("cs",supervisionInspectionVo.getManagementCity());//城市
        params.put("bxwr",askingRecord.getPerson());//被询问人
        params.put("fddbr", supervisionInspectionVo.getLegalRepresentative());//法定代表人
        params.put("xb",askingRecord.getGender());//性别
        params.put("nl",askingRecord.getAge());//年龄
        params.put("zz",askingRecord.getAddress());//住址，是填的
        params.put("lxdh",supervisionInspectionVo.getContactNumber());//联系电话
        params.put("hm",askingRecord.getCertificateNo());//身份证号
        params.put("zjmc",askingRecord.getCertificateType());//证件名称，类型
        params.put("xwjg",askingRecord.getAskingUnit());

        params.put("mz",supervisionInspectionVo.getNation());//民族
        params.put("zw", supervisionInspectionVo.getPosition());//职务


        params.put("endHour", askingRecord.getEndTime().substring(11,13));
        params.put("endMin", askingRecord.getEndTime().substring(14));
        params.put("jdy1", supervisionInspectionVo.getFirstSupervisorName());
        params.put("jdy2", supervisionInspectionVo.getSecondSupervisorName());
        List<RecordPDFVo> recordPDFVoList=new ArrayList<>();
        for (QA qa : qaList) {
            RecordPDFVo recordPDFVo=new RecordPDFVo();
            recordPDFVo.setXcbl("");
            recordPDFVo.setAnswer(qa.getAnswer());
            recordPDFVo.setQuestion(qa.getQuestion());
            recordPDFVoList.add(recordPDFVo);
        }
        params.put("recordPDFVoList",recordPDFVoList);
        params.put("startYear", askingRecord.getStartTime().substring(0,4));
        params.put("startMonth", askingRecord.getStartTime().substring(5,7));
        params.put("startDay", askingRecord.getStartTime().substring(8,10));
        params.put("startHour", askingRecord.getStartTime().substring(11,13));
        params.put("startMin", askingRecord.getStartTime().substring(14));
        params.put("xwdd",askingRecord.getAskingAddress());
        params.put("xwjg",askingRecord.getAskingUnit());
        params.put("zfzjhm1", supervisionInspectionVo.getFirstSupervisorNo());
        params.put("zfzjhm2", supervisionInspectionVo.getSecondSupervisorNo());
        if(upload1!=null)params.put("enInquiryUrl",upload1.getUrl());
        if(upload2!=null)params.put("firstSignUrl",upload2.getUrl());
        if(upload3!=null)params.put("secondSignUrl",upload3.getUrl());
        params.put("jcjg", supervisionInspectionVo.getSuperviseSector());//检查的单位的所属监督机构
        params.put("orgLevel", application.getOrgLevel());
        params.put("county", application.getCounty());
        String ss=JSON.toJSONString(params);
        return ss;
    }
    /*现场照片证据*/
    public static String exportPhotoPDF(SupervisionInspectionPhotoVo supervisionInspectionPhotoVo,FuzhouApplication application){
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("photoNum",supervisionInspectionPhotoVo.getPhotoNum());
        params.put("docTemplateUrl",supervisionInspectionPhotoVo.getDocTemplateUrl());//模板
        params.put("proveMatters",supervisionInspectionPhotoVo.getProveMatters());
        params.put("shootingTime",supervisionInspectionPhotoVo.getShootingTime());
        params.put("shootingLocation", supervisionInspectionPhotoVo.getShootingLocation());
        params.put("photographer",supervisionInspectionPhotoVo.getPhotographer());
        params.put("lawEnforcementPersonnel1",supervisionInspectionPhotoVo.getLawEnforcementPersonnel1());
        params.put("lawEnforcementCertificateNumber1",supervisionInspectionPhotoVo.getLawEnforcementCertificateNumber1());
        params.put("lawEnforcementPersonnel2",supervisionInspectionPhotoVo.getLawEnforcementPersonnel2());
        params.put("lawEnforcementCertificateNumber2",supervisionInspectionPhotoVo.getLawEnforcementCertificateNumber2());
        params.put("photoUrl",supervisionInspectionPhotoVo.getPhotoUrl());
        params.put("partySignatureUrl",supervisionInspectionPhotoVo.getPartySignatureUrl());
        params.put("orgLevel", application.getOrgLevel());
        params.put("county", application.getCounty());
        String ss=JSON.toJSONString(params);
        return ss;
    }
    /*现场笔录*/
    public static String inquiryRecord(SupervisionInspectionVo supervisionInspectionVo,FuzhouApplication application,String documentNo, String fileUrl, Upload upload1, Upload upload2, Upload upload3){
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        if(documentNo==null){
            params.put("bh"," ");//编号
        }else{
            params.put("bh",documentNo);//编号
        }
        params.put("dz", supervisionInspectionVo.getInspectionLocation());
        params.put("dsr", supervisionInspectionVo.getSupervisedUnitName());
        params.put("docTemplateUrl",fileUrl);
        params.put("endHour", supervisionInspectionVo.getInspectEndTime().substring(11,13));
        params.put("endMin", supervisionInspectionVo.getInspectEndTime().substring(14));
        params.put("fddbr", supervisionInspectionVo.getLegalRepresentative());
        params.put("jcdd", supervisionInspectionVo.getInspectionLocation());
        params.put("jcjg", supervisionInspectionVo.getSuperviseSector());//检查的单位的所属监督机构
        //params.put("jcqk",supervisionInspection.getSuperviseSector());//检查情况先不传
        params.put("jdy1", supervisionInspectionVo.getFirstSupervisorName());
        params.put("jdy2", supervisionInspectionVo.getSecondSupervisorName());
        params.put("lxdh", supervisionInspectionVo.getContactNumber());
        params.put("mz", supervisionInspectionVo.getNation());
        params.put("ptry", supervisionInspectionVo.getAccompanyName());
        params.put("startYear", supervisionInspectionVo.getInspectStartTime().substring(0,4));
        params.put("startMonth", supervisionInspectionVo.getInspectStartTime().substring(5,7));
        params.put("startDay", supervisionInspectionVo.getInspectStartTime().substring(8,10));
        params.put("startHour", supervisionInspectionVo.getInspectStartTime().substring(11,13));
        params.put("startMin", supervisionInspectionVo.getInspectStartTime().substring(14));
        params.put("xb", supervisionInspectionVo.getGender());
        params.put("zfzjhm1", supervisionInspectionVo.getFirstSupervisorNo());
        params.put("zfzjhm2", supervisionInspectionVo.getSecondSupervisorNo());
        params.put("zw", supervisionInspectionVo.getPosition());
        params.put("zz", supervisionInspectionVo.getManagementAddress());
        List<RecordPDFVo> recordPDFVoList=new ArrayList<>();
        RecordPDFVo recordPDFVo=new RecordPDFVo();
        recordPDFVo.setXcbl(StringUtil.isNullOrEmpty(supervisionInspectionVo.getInspectRecords())? "": supervisionInspectionVo.getInspectRecords());
        recordPDFVo.setAnswer("");
        recordPDFVo.setQuestion("");
        recordPDFVoList.add(recordPDFVo);
        params.put("recordPDFVoList",recordPDFVoList);
        if(upload1!=null)params.put("litigantSignUrl",upload1.getUrl());
        if(upload2!=null)params.put("firstSignUrl",upload2.getUrl());
        if(upload3!=null)params.put("secondSignUrl",upload3.getUrl());
        params.put("sfzh", supervisionInspectionVo.getCertificateNo());
        params.put("jdy1", supervisionInspectionVo.getFirstSupervisorName());
        params.put("jdy2", supervisionInspectionVo.getSecondSupervisorName());//监督员2
        params.put("dwmc", StringUtil.isNullOrEmpty(supervisionInspectionVo.getSupervisedUnitName2())?supervisionInspectionVo.getSupervisedUnitName():supervisionInspectionVo.getSupervisedUnitName2());//被监督单位名称
        params.put("ptr", supervisionInspectionVo.getAccompanyName());//陪同人
        params.put("jdyj", StringUtil.isNullOrEmpty(supervisionInspectionVo.getSupervisionOpinions())?"": supervisionInspectionVo.getSupervisionOpinions());//监督意见
        params.put("orgLevel", application.getOrgLevel());
        params.put("county", application.getCounty());
        String ss= JSON.toJSONString(params);
        return ss;
    }
    /*量化评级*/
    public static String quantitativeRecord(SupervisionInspectionVo supervisionInspectionVo,FuzhouApplication application,Upload upload1, Upload upload2,int totalScore,int shouldScore){
        int totalActualScore=0;int standardizedScore=0;int reasonableOmissionScore=0;
        List<GradeQuestionBankVo> gradeQuestionBankVoList=supervisionInspectionVo.getGradeQuestionBankVoList();
        for (GradeQuestionBankVo gradeQuestionBankVo : gradeQuestionBankVoList) {
            if("1".equals(gradeQuestionBankVo.getIsFaultiness())){
                reasonableOmissionScore=reasonableOmissionScore+gradeQuestionBankVo.getScore();
            }
        }
        standardizedScore=totalScore*100/shouldScore;
        Map<String, Object> params = new LinkedHashMap<String, Object>();
        params.put("totalActualScore",totalScore);//总得分
        params.put("standardizedScore",standardizedScore);//标化分
        params.put("level", supervisionInspectionVo.getGrade());//核定等级
        params.put("totalScore", shouldScore);//总分
        params.put("reasonableOmissionScore", reasonableOmissionScore);//合理缺项分
        params.put("shouldScore", shouldScore);//应得分
        params.put("supervisedUnitName", supervisionInspectionVo.getSupervisedUnitName());//单位名称
        params.put("legalRepresentative",supervisionInspectionVo.getLegalRepresentative());//负责人
        params.put("managementAddress", supervisionInspectionVo.getManagementAddress());//地址
        params.put("contactNumber","");//联系电话
    //    params.put("contactNumber", supervisionInspectionVo.getContactNumber());//联系电话
        params.put("healthLicenseNumber","" );//卫生许可证编号
//        params.put("healthLicenseNumber",supervisionInspectionVo.getCreditCode() );//卫生许可证编号
        params.put("number", "");//号码
        params.put("startYear", supervisionInspectionVo.getInspectStartTime().substring(0,4));//年
        params.put("startMonth",supervisionInspectionVo.getInspectStartTime().substring(5,7));//月
        params.put("startDay", supervisionInspectionVo.getInspectStartTime().substring(8,10));//日
        params.put("jcjg", supervisionInspectionVo.getSuperviseSector());//检查的单位的所属监督机构
        if(upload1!=null)params.put("imageUrl1",upload1.getUrl());//签名图片地址1(陪同人)
        if(upload2!=null)params.put("imageUrl2",upload2.getUrl());//签名图片地址2(监督人员)
        params.put("gradeQuestionBankPdfVoList",gradeQuestionBankVoList);//题库信息
        if(supervisionInspectionVo.getSpecialityDetail().contains("浴室")){
            params.put("reportType","沐浴场所");
        }else if(supervisionInspectionVo.getSpecialityDetail().contains("宾馆")||supervisionInspectionVo.getSpecialityDetail().contains("招待所")||supervisionInspectionVo.getSpecialityDetail().contains("旅店")){
            params.put("reportType","住宿业");
        }else if(supervisionInspectionVo.getSpecialityDetail().contains("游泳")||supervisionInspectionVo.getSpecialityDetail().contains("体育")){
            params.put("reportType","游泳场所");
        }else if(supervisionInspectionVo.getSpecialityDetail().contains("美容")||supervisionInspectionVo.getSpecialityDetail().contains("理发")){
            params.put("reportType","美容美发");
        }
        params.put("orgLevel", application.getOrgLevel());
        params.put("county", application.getCounty());
        String ss=JSON.toJSONString(params);
        return ss;
    }
}
